import { Singleton } from '../../../../framework/common/Singleton';
import MonsterBase from '../MonsterBase';
import Scarecrow from '../Scarecrow';

export enum MonsterID {
    Scarecrow = 'Scarecrow',
}
/**
 * 怪物创建器
 */
export class MonsterCreator extends Singleton<MonsterCreator>() {
    /**
     * 通过已有实体创建怪物
     * @param id ID
     * @param quality 品质
     * @param entity 实体
     */
    create(id: MonsterID, quality: number, entity: GameEntity): MonsterBase {
        let result: MonsterBase;
        switch (id) {
            case MonsterID.Scarecrow:
                result = new Scarecrow(entity);
                break;
            default:
                result = new MonsterBase(entity);
                break;
        }
        result.setQuality(quality);
        return result;
    }

    /**
     * 通过ID和位置创建怪物
     * @param id ID
     * @param quality 品质
     * @param position 位置
     */
    createByID(id: MonsterID, quality: number, position: GameVector3) {
        const entity: GameEntity = world.createEntity({ position })!;
        return this.create(id, quality, entity);
    }
}

const monsterCreator = MonsterCreator.instance;
export default monsterCreator;
